<?php
/**
 * 单位相关接口请求参数验证器
 * Created by PhpStorm.
 * User: LRChang
 * Date: 2018/6/11
 * Time: 10:39
 * Mail: hjklrchang@qq.com
 */

namespace app\adminapi\validate;

use app\base\validate\BaseValidate;

class CompanyValidate extends BaseValidate
{
    protected $rule = [
        'page' => 'isPositiveInt',
        'pagenum' => 'isPositiveInt',
//        'fields' => '',
        'where_json' => 'isWhereJson',

        'company_id' => 'require|isPositiveInt',
        'user_id' => 'require|isPositiveInt',
        'area_id' => 'integer|>=:0',
        'company_name' => 'require|max:100',
        'company_mode' => 'require|in:1,2',
        'short_name' => 'require|max:100',
        'address' => 'require|max:255',
        'linkman' => 'require|max:255',
        'phone' => 'require|integer|min:11|max:15',
        'remark' => 'max:255',
        'is_zhuanpiao' => 'in:0,1',
        'contractno' => 'max:100',
        'manage_dept' => 'max:255',
        'isreform' => 'in:0,1',
        'fundsform' => 'max:100',
        'orgn_grade' => 'max:100',
        'vehicle_nature' => 'max:255',
        'orgn_type' => 'max:255',
        'code' => 'max:20',
        'check_passenger_id' => 'integer',
//        'quota' => 'float|>=:0',
//        'used_quota' => 'float|>=:0',
//        'unit_quota' => 'float|>=:0',
//        'used_unit_quota' => 'float|>=:0',
        'is_limit' => 'in:0,1',
        'license' => 'max:255',
        'law_type' => 'in:1,2',
        'prop' => 'max:255',
        'sign' => 'in:1,9',
//        'note' => '',
        'state' => 'in:1,9',

        'company_ids' => 'require|checkIDs',
    ];

    // 默认值
    protected $default = [
        'page' => 1,
        'pagenum' => 20,
        'where_json' => '',
        'fields' => '*',
    ];

    protected $message = [
        'page.isPositiveInt' => '页数只能为正整数',
        'pagenum.isPositiveInt' => '每页数量只能为正整数',
        'fields.isNotEmpty' => '字段不能为空',
        'where_json.isWhereJson' => '不是合法的json字符串',

        'company_ids.checkIDs' => "company_ids 必须为正整数，多个请用','号连接"
    ];

    protected $scene = [
        'list' => ['page' ,'pagenum', 'fields', 'where_json'],
        'add' => [
            'user_id',
            'area_id',
            'company_name',
            'company_mode',
            'short_name',
            'address',
            'linkman',
            'phone',
            'remark',
            'is_zhuanpiao',
            'contractno',
            'manage_dept',
            'isreform',
            'fundsform',
            'orgn_grade',
            'vehicle_nature',
            'orgn_type',
            'code',
            'check_passenger_id',
//            'quota',
//            'used_quota',
//            'unit_quota',
//            'used_unit_quota',
            'is_limit',
            'license',
            'law_type',
            'prop',
            'sign',
            'note',
            'state',
        ],
        'edit' => [
            'company_id',
            'user_id',
            'area_id',
            'company_name',
            'company_mode',
            'short_name',
            'address',
            'linkman',
            'phone',
            'remark',
            'is_zhuanpiao',
            'contractno',
            'manage_dept',
            'isreform',
            'fundsform',
            'orgn_grade',
            'vehicle_nature',
            'orgn_type',
            'code',
            'check_passenger_id',
//            'quota',
//            'used_quota',
//            'unit_quota',
//            'used_unit_quota',
            'is_limit',
            'license',
            'law_type',
            'prop',
            'sign',
            'note',
            'state',
        ],
        'delete' => [ 'company_ids' ],
    ];
}